home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Allowing interrupts in interrupt code
- Date: 9 Apr 1996 09:03:01 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4ke1nlINNjcd@keats.ugrad.cs.ubc.ca>
- References: <3159B9DE.6140@igrin.co.nz>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <3159B9DE.6140@igrin.co.nz>,
- Steve Lowe <lowefam@igrin.co.nz> wrote:
- >I have a routine attached to the timer interrupt.
-
- Timer interrupts are not defined by the C language. You cannot write interrupt
- service routines in ANSI C. Your question is likely platform-specific.
-
- >However, sometimes it takes more than one clock tick to execute - which
- >causes endless headaches.
- >
- >Is there anything I can put in this routine so that an new interrupts
- >can carry on?
-
- Yes, you can put in a semaphore flag to indicate that you are currently doing
- busywork inside the interrupt handler. Then you reenable interrupts. When an
- interrupt arrives, it sees that the flag is set and will not enter the same
- region of code, but will instead do only basic housekeeping things like
- updating counters, calling other handlers in the interrupt chain and whatnot.
- It will not fiddle with the data that the first invocation is working on.
-
- The real solution is to do time-slicing so that your lengthy task can be done
- as a thread dispatched by a scheduler. In a typical (single-CPU) OS
- implementation, tasks that can be done quickly are done with interrupts
- disabled. Tasks that take longer are done inside a critical region protected by
- semaphores rather than by interrupt masking, so that other processes can
- execute, and interrupts can be handled.
- --
-
-